package com.CooKieTest;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/*
这个类用于清除Cookie
1.不设置有效期，关闭浏览器，自动失效
2.设置有效期时间为0
 */

@WebServlet("/c2")
public class CookieDemo02 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Cookie cookie = new Cookie("lastLoginTime",System.currentTimeMillis()+"");

        cookie.setMaxAge(0);
        resp.addCookie(cookie);

    }
}
